home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / tcoop10a.zip / DEMO.ZIP / TESTWIND.CPP < prev    next >
C/C++ Source or Header  |  1991-11-20  |  4KB  |  157 lines

  1. //
  2. //    WINDOWS.CPP
  3. //    version 1.00    11/15/91
  4. //    window demo uses Window, Menu and Control Classes
  5. //    copyright (c) 1991 by James S. Clark
  6. //    all rights reserved
  7. //
  8.  
  9.  
  10. #include <stdlib.h>
  11. #include <dos.h>    // pokeb()
  12. #include <conio.h>    // colors
  13.  
  14.  
  15. #include "window.hpp"
  16. #include "menu.hpp"
  17. #include "control.hpp"
  18.  
  19.  
  20. //    EXTERNALS
  21.  
  22. extern unsigned VideoBaseAddr;
  23.  
  24. colors  MICROCOLORS = { 0x3E, 0x3B, 0x30, 0x7E, 0x3F, 0x3E, 0x3F, 0x7F };
  25. colors  TURBOCOLORS = { 0x1E, 0x17, 0x1E, 0x5E, 0x1F, 0x1F, 0x1B, 0x5B };
  26.  
  27.  
  28. //    TEST MENU CONSTANTS
  29.  
  30.  
  31. char    *MAINMENU = "> \xF0 > File > Edit > Setup > Options > Window > Help ";
  32. char    *FILEMENU = ">Open...  Alt-A>New>Save>Save as...>->Directory>Quit\0";
  33.  
  34. char    *COMMANDMENU[] = {
  35.         "> \xF0 > File > Edit > Options > Window > Help ",
  36.         ">Copyright...>About...\0",
  37.         ">Open...  Alt-A>New>Save>Save as...>->Directory>Quit\0",
  38.         ">Cut>Move>Paste>Delete>Write block>Read block\0",
  39.         ">Memory>Display>Printer>Disk\0",
  40.         ">Close>Move>Resize>Zoom\0",
  41.         ">Dictionary>General>On Help\0"
  42. };
  43.  
  44. // ATTR - returns text attribute of fore/back colors
  45. int attr(int forecolor, int backcolor)
  46. {
  47.     return(backcolor << 4 | forecolor);
  48. }
  49.  
  50.  
  51. // CLEARDESK - clears the desk top
  52. void cleardesk()
  53. {
  54.     register int    i;
  55.     char        ccolor = attr(LIGHTGRAY, BLACK);
  56.  
  57.     for (i=0; i<4000; i+=2)
  58.         pokeb(VideoBaseAddr, i, 0xB0);
  59.         pokeb(VideoBaseAddr, i+1, ccolor);
  60. }
  61.  
  62.  
  63.  
  64. int    mastermenu(MenuBar *menubar, Menu *menu, char *menus[], colors *clr)
  65. {
  66.     int    x, y;
  67.         int     sel = 0, sel1 = 0, sel2 = 0;
  68.  
  69.     menubar = new MenuBar(NULL, 1, 1, NULL, menus[0], clr);
  70.     while (sel == 0) {
  71.         sel1 = menubar->select() + 1;
  72.         if (sel1 > 0) {
  73.             x = wherex() - 1;
  74.             y = wherey() + 1;
  75.             menu = new Menu(NULL, x, y, W_FRAME|W_EMBOSS|W_SHADOW, menus[sel1], clr);
  76.             sel2 = menu->select();
  77.             if (sel2 > 0) sel = sel1 * 100 + sel2;
  78.             if (sel2 == -2) {
  79.                 sel1--;
  80. //                if (sel1 < 0) sel1 = menubar->maxitems;
  81.             }
  82.             if (sel2 == -3) {
  83.                 sel1++;
  84. //                if (sel1 > menubar->maxitems) sel1 = 0;
  85.             }
  86.         }
  87.     }
  88.     return(sel);
  89. }
  90.  
  91.  
  92. main()
  93. {
  94.     Window    *theWindow[10];
  95.     MenuBar    *theMenuBar;
  96.     Menu     *theMenu;
  97.     Control *theCtrl[10];
  98.  
  99.     int    windnum = 9;
  100.     int    x, y;
  101.     int    i;
  102.  
  103.     randomize();
  104.  
  105.     theWindow[0]->startup();
  106.  
  107.     cleardesk();
  108.  
  109.     for (i=0; i<windnum; i++) {
  110.         x = 1 + random(53);
  111.         y = 1 + random(17);
  112.         theWindow[i] = new Window("MR. WINDOW", x, y, x+25, y+7, W_FRAME|W_TITLE|W_SHADOW, NULL);
  113.                 theWindow[i]->textbox(1, 1, 24, 6, random(3)+1,
  114.             "This is a text box from hell!!!! Hope you like it Dude!");
  115.         delay(250);
  116.         getch();
  117.     }
  118.     for (i=windnum-1; i>=0; i--) {
  119.         theWindow[i]->close();
  120.         delete theWindow[i];
  121.         delay(250);
  122.     }
  123.  
  124.     /* open a couple of test menus */
  125.  
  126. //      mastermenu(theMenuBar, theMenu, COMMANDMENU, &TURBOCOLORS);
  127.  
  128.     theMenuBar = new MenuBar(NULL, 1, 1, NULL, MAINMENU, &TURBOCOLORS);
  129.     theMenuBar->select();
  130.     theMenu = new Menu("File", 10, 10, W_FRAME|W_TITLE|W_EMBOSS|W_SHADOW, FILEMENU, &TURBOCOLORS);
  131.     theMenu->select();
  132.  
  133.     delay(500);
  134.     theMenu->close();
  135.     delay(500);
  136.     theMenuBar->close();
  137.  
  138.     /* open a test window with controls */
  139.  
  140.     theWindow[1] = new Window("CONTROL WINDOW", 5, 4, 75, 20, W_FRAME|W_TITLE|W_SHADOW, NULL);
  141.  
  142.     theCtrl[1] = new Control(theWindow[1], C_CHECK, "Completed", 10, 8, W_EMBOSS, 1, NULL);    theCtrl[2] = new Control(theWindow[1], C_BUTTON, " Load ", 10, 10, W_EMBOSS, 0, NULL);
  143.     theCtrl[3] = new Control(theWindow[1], C_FIELD, "Echo only", 10, 12, W_EMBOSS, 20, NULL);
  144.     theCtrl[4] = NULL;
  145.  
  146.     theCtrl[3]->setstr("Test Text          ");
  147.     theCtrl[3]->draw(0);
  148.     ControlSelect(&theCtrl[1]);
  149.  
  150.     for (i=1; i<4; i++) delete theCtrl[i];
  151.  
  152.     delay(500);
  153.     theWindow[1]->close();
  154.     delay(500);
  155.     return(0);
  156. }
  157.